<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class points_class extends CI_Model {
	
		
		public function list_points(){
			$query = $this->db->get_where('jtn_points',array('intDisabled'=>0));
			if ($query->num_rows() > 0){
				$result = $query->result_array();
				return $result;
			}
			else{
				return 0;
			}
		}
		public function get_available_points($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intUserID'=>$intID,'intPointsID'=>2));
			}
			$query = $this->db->get('jtn_users_points')->result_array();
			$query = current($query);
		
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function get_points_via_share($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intUserID'=>$intID,'intPointsID'=>1));
			}
			$query = $this->db->get('jtn_users_points')->result_array();
			$query = current($query);
		
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function get_earn_points($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intID'=>$intID));
			}
			$query = $this->db->get('jtn_earn_points')->result_array();
			$query = current($query);
		
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function update_points_via_share($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$intPoints = stripslashes(filter_var($post['intPoints'], FILTER_SANITIZE_STRING));
			$intPointsID = stripslashes(filter_var($post['intPointsID'], FILTER_SANITIZE_STRING));
			
			$data = array(
					'intPoints'=>$intPoints,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			
			$this->db->where(array('intUserID'=>$intID,'intPointsID'=>$intPointsID));
			$this->db->update('jtn_users_points',$data);
			
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function update_available_points($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$intPoints = stripslashes(filter_var($post['intPoints'], FILTER_SANITIZE_STRING));
			$intPointsID = stripslashes(filter_var($post['intPointsID'], FILTER_SANITIZE_STRING));
			
			$data = array(
					'intPoints'=>$intPoints,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			
			$this->db->where(array('intUserID'=>$intID,'intPointsID'=>$intPointsID));
			$this->db->update('jtn_users_points',$data);
			
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
	} // end class
?>